using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using OneSoft.EntityCore;
using OneSoft.DataAccess;
using BySoft.Server.Common.Entity;
using BySoft.Server.Common.Schema;

namespace BySoft.Server.DataAccess
{
    public partial class MdMaterialsmalltypeDA
	{
		

        private static string GetHeadSQL()
        {
            return @"SELECT A.*,b.MaterialTypeName 
                    FROM MD_MaterialSmallType A  left  join MD_MaterialType b
                    ON a.materialTypeId=b.materialTypeId
                    WHERE 1=1";
        }
        public static DataTable SelectList( string strMaterialTypeName,  int pageIndex, int pageSize, out int count)
        {
            try
            {
                #region SQL Server
                string strcmd = GetHeadSQL();

                DataAccessParameterCollection dpc = new DataAccessParameterCollection();

               
              

                if (!string.IsNullOrEmpty(strMaterialTypeName))
                {
                    strcmd += " and A.MaterialTypeName LIKE @MaterialTypeName";
                    dpc.AddWithValue("@MaterialTypeName", "%" + strMaterialTypeName + "%");
                }
              

                strcmd += " ORDER BY A.MaterialSmallTypeID DESC";

                return DataAccessCommon.ExecuteDataTablePaging(strcmd, pageIndex, pageSize, dpc, out count);
                #endregion
            }
            catch
            {
                throw;
            }
        }



        public static DataTable SelectByTypeID(string strMaterialTypeID,string strMaterialSmallTypeName, int pageIndex, int pageSize, out int count)
        {
            try
            {
                #region SQL Server
                string strcmd = GetHeadSQL();

                DataAccessParameterCollection dpc = new DataAccessParameterCollection();

                if (!string.IsNullOrEmpty(strMaterialTypeID))
                {
                    strcmd += " and A.MaterialTypeID = @MaterialTypeID";
                    dpc.AddWithValue("@MaterialTypeID", strMaterialTypeID.Trim() );
                }

                if (!string.IsNullOrEmpty(strMaterialSmallTypeName))
                {
                    strcmd += " and A.MaterialSamllTypeName LIKE @MaterialSamllTypeName";
                    dpc.AddWithValue("@MaterialSamllTypeName", "%" + strMaterialSmallTypeName + "%");
                }


                strcmd += " ORDER BY A.MaterialSmallTypeID DESC";

                return DataAccessCommon.ExecuteDataTablePaging(strcmd, pageIndex, pageSize, dpc, out count);
                #endregion
            }
            catch
            {
                throw;
            }
        }
      
    }
}

